package com.lottery.material.service.portal.portaluser.impl;

import com.lottery.material.dao.base.BaseDao;
import com.lottery.material.dao.portal.portaluser.FollowInfoDao;
import com.lottery.material.entity.portaluser.FollowInfo;
import com.lottery.material.entity.portaluser.PortalUserInfo;
import com.lottery.material.service.base.impl.BaseServiceImpl;
import com.lottery.material.service.portal.portaluser.FollowInfoService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @Author 肖拔赟
 * @Description 用户关注信息
 * @DATE Created on 2019-04-04 9:35
 */
@Service
@Slf4j
public class FollowInfoServiceImpl extends BaseServiceImpl<FollowInfo, Integer> implements FollowInfoService {

    @Autowired
    private  FollowInfoDao followInfoDao;

//    @PersistenceContext
//    private EntityManager entityManager;

    @Override
    public BaseDao<FollowInfo, Integer> getBaseDao() {
        return followInfoDao;
    }

    @Override

    public Page<PortalUserInfo> findFollowByUserId(String userId, Pageable pageable) {
        log.info("findByUserId........{}", System.currentTimeMillis());

        Page<PortalUserInfo> page = followInfoDao.findFollowByUserId(userId,pageable);

        return page;
    }

    @Override
    public FollowInfo findByUserIdAndFollowUserId(String userId, String followUserId) {
        return followInfoDao.findByUserIdAndFollowUserId(userId, followUserId);
    }


//    public List<FollowInfo> findByUserId2(Integer userId) {
//        log.info("findByUserId........{}", System.currentTimeMillis());
//        String hqlStr = "from FollowInfo where 1=1 and  userId =:userId";
//
//        Query query = entityManager.createQuery(hqlStr, FollowInfo.class);
//        query.setParameter("userId", userId);
//
//        query.setFirstResult(0);
//        query.setMaxResults(10);
//        List<FollowInfo> list = query.getResultList();
//
//        return list;
//    }

    /**
     * 给hql参数设置值
     * @param query 查询
     * @param params 参数
     */
//    private void setParameters(Query query, Map<String,Object> params){
//        for(Map.Entry<String,Object> entry:params.entrySet()){
//            query.setParameter(entry.getKey(),entry.getValue());
//        }
//    }

}
